<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="./widget/base"></div>
</head>
<body>
<div id="operationLogToolbar">
    <nimrod:security authority="/COMPONENT/SYSTEM/OPERATION_LOG/PAGE_ALL/OPERATION_LOG_DELETE_ALL">
        <a href="javascript:" class="easyui-linkbutton" iconCls="iconfont icon-close"
           onclick="operationLogDeleteAll();">删除</a>
    </nimrod:security>
    <nimrod:security authority="/COMPONENT/SYSTEM/OPERATION_LOG/PAGE_ALL/OPERATION_LOG_CLEAR_ALL">
        <a href="javascript:" class="easyui-linkbutton" iconCls="iconfont icon-close" onclick="operationLogClearAll();">清空日志</a>
    </nimrod:security>
</div>
<table id="operationLog"></table>

<script type="text/javascript">
    $(function () {
        var OPERATION_TYPE = [];
        var columns = [
            {field: 'checkbox', checkbox: true},
            {field: 'id', title: 'ID'},
            {
                field: 'view', title: '操作', formatter: function (value, row, index) {
                    return '<a href="javascript:" onclick="operationLogViewDialog(' + row.id + ')">查看</a>';
                }
            },
            {field: 'username', title: '访问用户'},
            {field: 'ipAddress', title: '用户 IP'},
            {
                field: 'operationType', title: '操作类型', formatter: function (value, row, index) {
                    return expressui.grid.formatter(value, OPERATION_TYPE);
                }
            },
            {field: 'operation', title: '操作说明'},
            {field: 'consumingTime', title: '请求耗时（毫秒）'},
            {field: 'requestUrl', title: '请求地址（url）'},
            {field: 'requestMethod', title: '请求方法'},
            {field: 'requestParameter', title: '请求参数'},
            {field: 'acceptLanguage', title: '请求语言'},
            {field: 'referer', title: '请求来源'},
            {field: 'userAgent', title: '用户代理'},
            {field: 'handler', title: 'Handler'},
            {field: 'stackTrace', title: '异常堆栈'},
            {field: 'sessionId', title: 'Session ID'},
            {field: 'cookie', title: 'Cookie'},
            {field: 'status', title: '响应状态码'},
            {field: 'gmtCreated', title: '创建时间'}
        ];
        $('#operationLog').datagrid(expressui.grid.create, {
            title: '操作日志',
            columns: [columns],
            url: Url.System.Api.OPERATION_LOG + '/page_all',
            onBeforeLoad: function (param) {
                util.ajax({
                    url: Url.System.Api.DICTIONARY + '/list_all_by_key/OPERATION_TYPE',
                    success: function (data) {
                        if (data) {
                            OPERATION_TYPE = data;
                        }
                    }
                });
            }
        });
    });

    function operationLogViewDialog(id) {
        $('#operationLogViewDialog').dialog(expressui.dialog.create, {
            title: '查看',
            width: 600,
            height: 430,
            href: Url.System.Page.OPERATION_LOG + '/view_dialog',
            get: {url: Url.System.Api.OPERATION_LOG + '/one/' + id, method: 'get'},
            buttons: [{
                text: '关闭',
                iconCls: 'iconfont icon-close',
                handler: expressui.dialog.close
            }]
        });
    }

    function operationLogDeleteAll() {
        $('#operationLog').datagrid(expressui.grid.postCheckedLessOneOrShowAlert, {
            url: Url.System.Api.OPERATION_LOG + '/delete_all',
            method: 'post',
            success: '删除成功',
            reload: {type: 'datagrid', selector: '#operationLog'}
        });
    }

    function operationLogClearAll() {
        $.messager.confirm('信息', '确定要操作吗', function (ok) {
            if (ok) {
                $.ajax({
                    url: Url.System.Api.OPERATION_LOG + '/clear_all',
                    type: 'POST',
                    dataType: 'JSON',
                    success: function (data) {
                        $.messager.show({title: '信息', msg: '操作成功'});
                        $('#operationLog').datagrid('reload');
                    },
                    error: function (xhr) {
                        if (xhr.status !== 200) {
                            $.messager.alert('信息', '操作失败：' + xhr.responseJSON.message, 'error');
                        } else {
                            $.messager.show({title: '信息', msg: '操作成功'});
                            $('#operationLog').datagrid('reload');
                        }
                    }
                })
            }
        });

    }

</script>

</body>
</html>